<div class="tabbable tabs-left">
    <ul class="nav nav-tabs">
        <li><h5><?php echo $this->translate('商品信息'); ?></h5></li>
        <li class="active"><a data-toggle="tab" href="#item_a"><?php echo $this->translate('基本信息'); ?></a></li>
        <li class=""><a data-toggle="tab" href="#item_c"><?php echo $this->translate('商品列表'); ?></a></li>
    </ul>
    <form class="form-horizontal" method="post" name="theme_form" id="theme_form">
        <input type="hidden" name="item_id" value="<?php echo $this->item_info->item_id; ?>">
        <input type="hidden" name="theme_id" value="<?php echo $this->item_info->theme_id; ?>">
        <div class="tab-content">
            <div id="sticky_navigation" style="height:30px;border-bottom:4px solid #DFDFDF;">
                <div class="pull-left" style="font-size:16px;line-height:30px;"><strong><?php echo $this->translate('编辑'); ?><?php echo $this->translate('商品'); ?></strong></div>
                <div id="sticky_navigation_right" class="pull-right">
                    <a href="<?php echo $this->url('admintheme/default', array('action'=>'goodsList'), array('query'=>array('theme_id'=>$this->item_info->theme_id))); ?>" class="btn btn-small"><i class="icon-arrow-left"></i> <?php echo $this->translate('返回商品设置'); ?></a>&nbsp;
                    <a href="<?php echo $this->serverUrl(true); ?>" class="btn btn-small btn-warning"><i class="icon-repeat icon-white"></i> <?php echo $this->translate('刷新'); ?></a>&nbsp;
                    <button type="submit" class="btn btn-small btn-primary"><i class="icon-ok icon-white"></i> <?php echo $this->translate('保存'); ?></button>&nbsp;
                    <a href="<?php echo $this->myviewalias()->dbshopHelpUrl('theme_set'); ?>" target="_blank" class="btn btn-small btn-info"><i class="icon-info-sign icon-white"></i> <?php echo $this->translate('查看帮助说明'); ?></a>
                </div>
            </div>
            <div id="item_a" class="tab-pane active">
                <div class="well admin_add_header_well"><?php echo $this->translate('基本信息'); ?></div>
                <div class="well admin_add_well">
                    <div class="message_one">
                    </div>
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('类型名称'); ?><span class="must_add_value">*</span>：</label>
                        <div class="controls">
                            <input type="text" id="item_title"  name="item_title" value="<?php echo ($this->item_info ? $this->escapeHtml($this->item_info->item_title) : ''); ?>" class="span10">
                        </div>
                    </div>
                </div>
            </div>

            <div id="item_c" class="tab-pane">
                <div class="well admin_add_header_well"><?php echo $this->translate('商品列表'); ?></div>
                <div class="well admin_add_well">
                    <div class="message_one">
                    </div>
                    <div class="control-group">
                        <input type="text" placeholder="<?php echo $this->translate('请输入需要添加的商品部分或者全部名称'); ?>" id="tag_goods_keyword" name="tag_goods_keyword"  value="" class="span5"><input type="hidden" name="tag_goods_id" id="tag_goods_id" value="" />&nbsp;&nbsp;<button type="button" onclick="add_goods_js();" class="btn btn-small btn-primary"><i class="icon-plus icon-white"></i> <?php echo $this->translate('点击添加商品'); ?></button>
                        <i class="cus-help shop_admin_help_note" data-content="<?php echo $this->translate('在输入框中输入商品部分或者全部名称，然后点击添加按钮，即可添加商品'); ?>"></i>
                    </div>
                    <table class="table table-hover" id="list_goods_show">
                    </table>
                </div>
            </div>
        </div>
    </form>
</div>
<link href="<?php echo $this->basePath('public/js/jquery-autocomplete/jquery.autocomplete.css'); ?>" rel="stylesheet">
<script src="<?php echo $this->basePath('public/js/jquery-autocomplete/jquery.autocomplete.min.js'); ?>"></script>
<script>

    //jquery-autocomplete查询商品
    $("#tag_goods_keyword").autocomplete("<?php echo $this->url('goods/default',array('action'=>'autocompleteGoodsSearch')); ?>", {
        //mustMatch: true,
        max: 20,
        minChars:1,
        scrollHeight:400
    });
    $("#tag_goods_keyword").result(function(event, data, formatted) {
        if (data) $("#tag_goods_id").val(data[1]);
    });
    //添加商品
    function add_goods_js() {
        var goods_id = $('#tag_goods_id').val();
        if(goods_id == '') {
            alert('<?php echo $this->translate('该商品不存在，请从新选择！'); ?>');
            return false;
        }
        $.post("<?php echo $this->url('admintheme/default',array('action'=>'addGoods')); ?>",{item_id:<?php echo $this->item_info->item_id; ?>,goods_id:goods_id},
            function(data){
                if(data.state == 'true') {
                    $('#tag_goods_keyword').val('');
                    $.get('<?php echo $this->url('admintheme/default',array('action'=>'listGoods')); ?>',{item_id:<?php echo $this->item_info->item_id; ?>}, function(html){
                        $("#list_goods_show").html(html);
                    });
                } else if(data.state == 'have') {
                    alert('<?php echo $this->translate('该商品已经存在，无需再次添加！'); ?>');
                } else {
                    alert('<?php echo $this->translate('商品添加失败！'); ?>');
                }
            },'json');
    }
    function del_goods_js(item_id, theme_goods_id) {
        if(window.confirm('<?php echo $this->translate('您确实要删除该商品显示吗？'); ?>')) {
            $.post("<?php echo $this->url('admintheme/default',array('action'=>'delGoods')); ?>",{item_id:item_id,theme_goods_id:theme_goods_id},
                function(data){
                    if(data != 'false') {
                        $.get('<?php echo $this->url('admintheme/default',array('action'=>'listGoods')); ?>',{item_id:<?php echo $this->item_info->item_id; ?>}, function(html){
                            $("#list_goods_show").html(html);
                        });
                        return true;
                    } else {
                        alert('<?php echo $this->translate('商品删除失败！'); ?>');
                    }
                });
        }
        return false;
    }

    $.get('<?php echo $this->url('admintheme/default',array('action'=>'listGoods')); ?>',{item_id:<?php echo $this->item_info->item_id; ?>}, function(html){
        $("#list_goods_show").html(html);
    });

    <?php if ($this->success_msg != '') { ?>
    show_message('.message_one','<?php echo date("Y-m-d H:i:s",time()); ?>','<?php echo $this->success_msg; ?>','alert-success');
    <?php } ?>
</script>
